/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include "PlanetWars2dRT-core/specific/model/planet.h"


EXTERN_C_BEGIN


void
planet_init_first_time_only_default(planet_t* a_planet)
{
  planet_set_default(a_planet);
  observers_init_first_time_only(&a_planet->observers);
}

void
planet_destructor(planet_t* a_planet)
{
  if(a_planet != NULL)
    {
      observers_clear(&a_planet->observers);
    }
}

/* Other(s) */

#define STRUCT_PROPRIETY_EQUALS(struct1, struct2, propriety) \
  ( (struct1).propriety == (struct2).propriety )

bool
planet_equals_except_observers(const planet_t* planet1,
			       const planet_t* planet2)
{
  return
    planet1 == planet2 ||
    (planet1 != NULL && planet2 != NULL &&
     POSITION_2D_EQUALS(planet1->position, planet2->position) &&
     SIZE_2D_EQUALS(planet1->size, planet2->size) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, life_current) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, life_max) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, producing_capacity) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, nb_updates_to_produce) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2,
			     nb_updates_before_next_production) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, produce_when_neutral) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, player_index) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, level_current) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, level_max) &&
     STRUCT_PROPRIETY_EQUALS(*planet1, *planet2, level_changer));
}


EXTERN_C_END
